﻿angular.module('app.common').directive('treeView', ['$compile', function ($compile) {
	return {
		restrict: 'A',
		link: {
			post: function postLink(scope, element, attrs) {
				// Build a "tree" of nodes using the children attribute
				element.html('').append($compile('<ul>' +
						'<li data-ng-repeat="node in ' + attrs.items + '" data-ng-class="node.nodeClass">' +
							'<img data-ng-click="' + attrs.toggleNode + '(node)" data-ng-src="/Content/Images/{{node.imgsrc}}.png"></img>' +
							'<a data-ng-click="' + attrs.selectNode + '(node)"' +
							'">{{node.' + attrs.nodeLabel + '}}</a>' +
							'<div data-ng-hide="node.collapsed" data-tree-id="node[nodeLabel]" data-tree-view="" data-items="node.' + attrs.nodeChildren + '" data-node-id="nodeId"' +
							' data-node-label="' + attrs.nodeLabel + '" data-node-children="' + attrs.nodeChildren + '" data-toggle-node="' + attrs.toggleNode +
							'" data-select-node="' + attrs.selectNode + '"></div>' +
						'</li>' +
					'</ul>')(scope));
				
			}
		}
	}
}]);
